/**
 * 
 */
package soa.security.domain;

import javax.naming.Name;

import org.apache.commons.lang3.StringUtils;
import org.springframework.ldap.odm.annotations.Attribute;
import org.springframework.ldap.odm.annotations.DnAttribute;
import org.springframework.ldap.odm.annotations.Entry;
import org.springframework.ldap.odm.annotations.Id;
import org.springframework.ldap.odm.annotations.Transient;
import org.springframework.ldap.support.LdapNameBuilder;

import soa.security.Constants;

/**
 * @author Cre.Gu
 *
 */
@Entry(objectClasses = { "zjtzsw-region", "domain", "zjtzsw-bid", "zjtzsw-top" })
public final class Region extends SoaBid {

	private static final long serialVersionUID = 8023688494452908195L;

	@Id
	private Name dn;

	private String dc;

	@Attribute(name = "o")
	private String name;

	@Attribute(name = "ccode")
	private String code;

	@DnAttribute(value = "bid")
	private String bid;
	
	private String regionLevel;

	@Transient
	private String parentDn;
	@Transient
	private Region parent;

	private int priority;

	public Region() {
	}

	public Region(String dc) {
		super();
		this.dc = dc;
	}

	public Region(String name, String code) {
		super();
		this.name = name;
		this.code = code;
	}

	public Region(String bid, String name, String code) {
		super();
		this.bid = bid;
		this.name = name;
		this.code = code;
	}

	public static Region root() {
		Region region = new Region("RE0000", "根目录", "000000");
		region.setDc("root");
		return region;
	}

	public Name buildDn() {
		LdapNameBuilder builder = LdapNameBuilder.newInstance();
		if (StringUtils.isNotBlank(parentDn))
			builder.add(parentDn);

		builder.add(Constants.BID, getBid());
		return builder.build();
	}

	public Name getDn() {
		return dn;
	}

	public void setDn(Name dn) {
		this.dn = dn;
	}

	public String getDc() {
		return dc;
	}

	public void setDc(String dc) {
		this.dc = dc;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getParentDn() {
		return parentDn;
	}

	public void setParentDn(String parentDn) {
		this.parentDn = parentDn;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getBid() {
		return bid;
	}

	public void setBid(String bid) {
		this.bid = bid;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	public Region getParent() {
		return parent;
	}

	public void setParent(Region parent) {
		this.parent = parent;
	}

	public String getRegionLevel() {
		return regionLevel;
	}

	public void setRegionLevel(String regionLevel) {
		this.regionLevel = regionLevel;
	}
}
